package ltd.hxya.novel.book.controller;

import ltd.hxya.novel.book.service.impl.LastCrawlIndexServiceImpl;
import ltd.hxya.novel.common.bean.Result;
import ltd.hxya.novel.common.to.book.BookTo;
import ltd.hxya.novel.entity.crawl.LastCrawlIndex;
import ltd.hxya.novel.entity.rowdata.NovelRowData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/book/lastCrawlIndex")
public class LastCrawlIndexController {

    @Autowired
    private LastCrawlIndexServiceImpl lastCrawlIndexService;

    @RequestMapping("/saveLastIndex")
    public Result saveLastIndex(@RequestBody List<NovelRowData> novelRowDataList){
        lastCrawlIndexService.saveLastIndex(novelRowDataList);
        return Result.success();
    }

    @PostMapping("/getLastIndex")
    public Result<LastCrawlIndex> getLastIndex(@RequestBody BookTo book){
        LastCrawlIndex lastCrawlIndex =lastCrawlIndexService.getLastIndex(book);
        return Result.success(lastCrawlIndex);
    }

    @GetMapping("/lastIndexList")
    public Result<List<LastCrawlIndex>> lastIndexList (@RequestParam("SourceId") Integer sourceId){
        List<LastCrawlIndex> lastCrawlIndices = lastCrawlIndexService.lastIndexList(sourceId);
        return Result.success(lastCrawlIndices);
    }
}
